//
//  MBDCommonCell.swift
//  MasterBoy
//
//  Created by kyson on 2023/3/28.
//

import Foundation
import UIKit


class MBDCommonCell: UITableViewCell {
    
    var separateLine:UIView!
    var commonBackgroundView : UIView!
    var rightArrowImage : UIImageView!
    var innerLocation : MBDCellLocation?
    var cellModel : Any!

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.initialize()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        self.initialize()
    }
    
    private func initialize() {
        commonBackgroundView = UIView()
        
        self.contentView.addSubview(commonBackgroundView)
        commonBackgroundView.snp.makeConstraints { make in
            make.center.equalTo(self.contentView)
            make.left.equalTo(MBDCommonCellModel.MarginLeftAndRightBackgroundView)
            make.top.equalTo(self.contentView)
        }
        
        rightArrowImage = UIImageView()
        rightArrowImage.image = UIImage(named: "arrow-right")
        rightArrowImage.contentMode = UIView.ContentMode.scaleAspectFit
        rightArrowImage.isHidden = true
        commonBackgroundView.addSubview(rightArrowImage)
        
        separateLine = UIView()
        separateLine.setDynamicSeperateLineColor()

        self.commonBackgroundView.addSubview(separateLine)
        
        separateLine.snp.makeConstraints { make in
            make.left.equalTo(15)
            make.height.equalTo( 1 / UIScreen.main.scale)
            make.right.equalTo(self.commonBackgroundView)
            make.bottom.equalTo(self.commonBackgroundView)
        }
        
        rightArrowImage.snp.makeConstraints { make in
            make.right.equalTo(self.commonBackgroundView).offset(-15)
            make.centerY.equalTo(self.commonBackgroundView)
            make.size.equalTo(CGSizeMake(14, 14))
        }
    }
    
    var location : MBDCellLocation? {
        
        didSet {
            if self.location == .top {
                commonBackgroundView.layer.cornerRadius = 6
                commonBackgroundView.layer.maskedCorners = CACornerMask(rawValue: CACornerMask.layerMinXMinYCorner.rawValue | CACornerMask.layerMaxXMinYCorner.rawValue)
            } else if self.location == .bottom {
                commonBackgroundView.layer.cornerRadius = 6
                commonBackgroundView.layer.maskedCorners = CACornerMask(rawValue: CACornerMask.layerMinXMaxYCorner.rawValue | CACornerMask.layerMaxXMaxYCorner.rawValue)
            } else {
                commonBackgroundView.layer.cornerRadius = 0
            }
        }
    }
    
    var accessable:Bool! {
//        arrow-right
        didSet {
            if(self.accessable) {
                self.rightArrowImage.isHidden = false
            } else {
                self.rightArrowImage.isHidden = true
            }
        }
    }
}


class MBDCommonCellModel: NSObject {
    static let MarginLeftAndRightBackgroundView : CGFloat = 8
    
    func cellHeight() -> CGFloat {
        return 55
    }
}
